package Foundmentation;

public class Function {
    public static void main(String[] args) {
 //       print(1234);
//        System.out.println("\r");
//        System.out.println(add(5));
//        System.out.println(fibonacci_sequence(10));
//        System.out.println(max3(5,8,6));
//          System.out.println(factorial(5));
//          System.out.println(factorialSum(5));
//        Scanner scanner = new Scanner(System.in);
//          int count=3;
//          while (count!=0){
//              System.out.println("请输入密码");
//              String password = scanner.nextLine();
//              if(password.equals("123")){
//                  System.out.println("登录成功");
//                  break;
//              }
//              else{
//                  count--;
//                  System.out.println("你还有"+ count + "次机会");
//              }
//          }
//        System.out.println(composition_Of_number_Sum(123));
//        System.out.println(fibonacci(5));


        tower(3, 'A','B', 'C');

    }

    public static void print(int n){
        if(n<10){
            System.out.print(n + " ");
            return;
        }
        print(n/10);
        System.out.print(n % 10 + " ");
    }
    public static int add(int n) {
        if (n <= 1) {
            return n;
        }
        return n + add(n-1);
    }

    public static int fibonacci_sequence(int n){
        int start = 1;
        int end = 1;
        int cur = 0;
        for (int i = 3; i <=n ; i++) {
            cur  = start + end;
            start = end;
            end  = cur;
        }
        return cur;
    }

    public static int max2(int a,int b){
        return a >b?a:b;
    }

    public static int max3(int a,int b,int c ){
        int m = max2(a,b);
        return max2(m,c);
    }

    public static int factorial(int n){
        if(n<=1){
            return n;
        }
        int ret= n * factorial(n-1);
        return ret;
    }

    public static int factorialSum(int n){
        int sum = 0;
        for (int i = 1; i <=n ; i++) {
            sum = sum + factorial(i);
        }
        return sum;
    }


    public static int composition_Of_number_Sum(int n){
        int sum = 0;
        if(n<10){
            return n;
        }

        sum =  n % 10 + composition_Of_number_Sum(n/10);
        return sum;
    }
    public static int fibonacci(int n){

        if(n<3){
            return 1;
        }
       return  fibonacci(n-1)+fibonacci(n-2);
    }

   public static void tower(int pan,char a, char b, char c)//a为原塔，b为暂存塔，c为目标塔
   {

       if(pan == 1){
           move(1,a,c);
           return;
        }
       tower(pan-1,a,c,b);//将pan-1个盘子从a塔移向b塔c塔暂存
       move(pan,a,c);//将第pan个盘子移向目标塔
       tower(pan-1,b,a,c);//将剩下的pan-1个盘子从b塔移向c塔a塔暂存
    }
    public static void move(int pan,char x,char y){
        System.out.println("将编号为"+pan+"的盘子从"+x+"移向"+y);
    }
}